# HarmonyOS Project Preview Test
Write-Host "=== HarmonyOS Project Preview Test ===" -ForegroundColor Green

# Check for private property issues
Write-Host "`n1. Checking for private property issues..." -ForegroundColor Yellow

$myRehabFile = "entry\src\main\ets\pages\myRehabilitationPlans.ets"
if (Test-Path $myRehabFile) {
    $content = Get-Content $myRehabFile -Raw
    
    # Check if private properties are still present in component definitions
    $privateIssues = @()
    if ($content -match "struct PlanCard[\s\S]*?private plan:") {
        $privateIssues += "PlanCard still has private plan property"
    }
    if ($content -match "struct PlanCard[\s\S]*?private onClick:") {
        $privateIssues += "PlanCard still has private onClick property"
    }
    if ($content -match "struct HistoryPlanCard[\s\S]*?private plan:") {
        $privateIssues += "HistoryPlanCard still has private plan property"
    }
    if ($content -match "struct HistoryPlanCard[\s\S]*?private onClick:") {
        $privateIssues += "HistoryPlanCard still has private onClick property"
    }
    
    if ($privateIssues.Count -eq 0) {
        Write-Host "SUCCESS: No private property issues found" -ForegroundColor Green
        
        # Check if @Prop decorator is used
        if ($content -match "@Prop plan:") {
            Write-Host "SUCCESS: @Prop decorator is properly used" -ForegroundColor Green
        } else {
            Write-Host "WARNING: @Prop decorator not found" -ForegroundColor Yellow
        }
    } else {
        Write-Host "ERROR: Found private property issues:" -ForegroundColor Red
        foreach ($issue in $privateIssues) {
            Write-Host "  - $issue" -ForegroundColor Red
        }
    }
} else {
    Write-Host "ERROR: myRehabilitationPlans.ets file not found" -ForegroundColor Red
}

# Check project structure
Write-Host "`n2. Checking project structure..." -ForegroundColor Yellow
$projectFiles = @(
    "entry\src\main\ets\pages\Index.ets",
    "entry\src\main\ets\pages\injuryAssessment.ets", 
    "entry\src\main\ets\pages\rehabilitationLibrary.ets",
    "entry\src\main\ets\pages\myRehabilitationPlans.ets",
    "entry\src\main\ets\pages\rehabilitationPlan.ets"
)

$allFilesExist = $true
foreach ($file in $projectFiles) {
    if (Test-Path $file) {
        Write-Host "OK: $file" -ForegroundColor Green
    } else {
        Write-Host "MISSING: $file" -ForegroundColor Red
        $allFilesExist = $false
    }
}

Write-Host "`n=== Test Results ===" -ForegroundColor Green
if ($allFilesExist -and $privateIssues.Count -eq 0) {
    Write-Host "SUCCESS: All issues have been fixed" -ForegroundColor Green
    Write-Host "SUCCESS: Project should now preview correctly in DevEco Studio" -ForegroundColor Green
} else {
    Write-Host "ERROR: Some issues remain" -ForegroundColor Red
}

Write-Host "`n=== Next Steps ===" -ForegroundColor Cyan
Write-Host "1. Reopen project in DevEco Studio" -ForegroundColor White
Write-Host "2. Wait for project indexing to complete" -ForegroundColor White
Write-Host "3. Try previewing Index.ets page" -ForegroundColor White
Write-Host "4. Check the previewer log for any remaining errors" -ForegroundColor White